package lumis.portal.progress;

import java.security.InvalidParameterException;
import java.sql.Timestamp;


/**
 * Config class for Progress properties
 *
 * @version $Revision: 7225 $ $Date: 2007-06-05 16:28:20 -0300 (Tue, 05 Jun 2007) $
 * @since 4.0.7
 */
public class ProgressConfig
{
	java.util.Date dateNow = new java.util.Date();

	public enum Type { 
		STEP, ERROR, WARNING, INFO, ABORT, CANCELLED, BEGIN, END_OK, END_ERROR, SCRIPT; 
		
		public int toInt()
		{
			switch (this)
			{
				case STEP: return 0;
				case ERROR: return 1;
				case WARNING: return 2;
				case INFO: return 3;
				case ABORT: return 4;
				case CANCELLED: return 5;
				case BEGIN: return 6;
				case END_OK: return 7;
				case END_ERROR: return 8;
				case SCRIPT: return 9;
				default: return 0;
			}
		}

		public static ProgressConfig.Type valueOf(int value)
		{
			switch (value)
			{
				case 0: return STEP;
				case 1: return ERROR;
				case 2: return WARNING;
				case 3: return INFO;
				case 4: return ABORT;
				case 5: return CANCELLED;
				case 6: return BEGIN;
				case 7: return END_OK;
				case 8: return END_ERROR;
				case 9: return SCRIPT;
				default: throw new InvalidParameterException();
			}
		}
		
	};
	
	private String processId;
	private int overallMax;
	private int overallValue;
	private int itemMax;
	private int itemValue;
	private Timestamp createdDateTime = new Timestamp(dateNow.getTime());
	private boolean lastMessage = false;
	private String message;
	private Type type = Type.STEP;
	private int elapsedTime;
	private String innerProgressId = null;
	
	public ProgressConfig(String processId, int overallMax, int overallValue, int itemMax, int itemValue, String message, Type type, boolean lastMessage)
	{
		this.processId = processId;
		this.overallMax = overallMax;
		this.overallValue = overallValue;
		this.itemMax = itemMax;
		this.itemValue = itemValue;
		this.lastMessage = lastMessage;
		this.message = message;
		this.type = type;
	}

	public ProgressConfig(String processId, int overallMax, int overallValue, int itemMax, int itemValue, String message, Type type, boolean lastMessage, int elapsedTime)
	{
		this(processId, overallMax, overallValue, itemMax, itemValue, message, type, lastMessage);
		this.elapsedTime = elapsedTime;
	}

	public Timestamp getCreatedDateTime()
	{
		return createdDateTime;
	}
	public void setCreatedDateTime(Timestamp createdDateTime)
	{
		this.createdDateTime = createdDateTime;
	}

	public boolean isLastMessage()
	{
		return lastMessage;
	}
	public void setLastMessage(boolean lastMessage)
	{
		this.lastMessage = lastMessage;
	}
	
	public String getMessage()
	{
		return message;
	}
	public void setMessage(String message)
	{
		this.message = message;
	}
	
	public String getProcessId()
	{
		return processId;
	}
	public void setProcessId(String processId)
	{
		this.processId = processId;
	}

	public Type getType()
	{
		return type;
	}
	public void setType(Type type)
	{
		this.type = type;
	}

	public int getItemMax()
	{
		return itemMax;
	}
	public void setItemMax(int itemMax)
	{
		this.itemMax = itemMax;
	}

	public int getItemValue()
	{
		return itemValue;
	}
	public void setItemValue(int itemValue)
	{
		this.itemValue = itemValue;
	}

	public int getOverallMax()
	{
		return overallMax;
	}
	public void setOverallMax(int overallMax)
	{
		this.overallMax = overallMax;
	}

	public int getOverallValue()
	{
		return overallValue;
	}
	public void setOverallValue(int overallValue)
	{
		this.overallValue = overallValue;
	}

	public int getElapsedTime()
	{
		return elapsedTime;
	}
	public void setElapsedTime(int elapsedTimeMillis)
	{
		this.elapsedTime = elapsedTimeMillis;
	}

	public long calculateRemainingTimeMillis()
	{
		if (elapsedTime < 3000)
			return -1;
		if (overallMax == overallValue)
			return 0;
		if (overallValue == 0)
			return -1; // maximum value 
		return elapsedTime * (overallMax - overallValue) / overallValue;
	}

	public String getInnerProgressId()
	{
		return innerProgressId;
	}

	public void setInnerProgressId(String innerProgressId)
	{
		this.innerProgressId = innerProgressId;
	}
	
}

